<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <meta content='' name='description'>
    <meta content='Nils Nordman' name='author'>
    <link href='/images/howl.png' rel='shortcut icon'>
    <title>Howl :: Spec - howl.ustrings</title>
    <link href="/stylesheets/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/syntax.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/howl.css" media="screen" rel="stylesheet" type="text/css" />
    <script src="https://code.jquery.com/jquery-1.12.3.min.js" type="text/javascript"></script>
    <script src="/javascripts/bootstrap.min.js" type="text/javascript"></script>
    
    <link href='//fonts.googleapis.com/css?family=Josefin+Slab' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
  </head>
  <body class='doc doc_spec doc_spec_ustring_spec'>
    <div class='container'>
      <div class='masthead'>
        <ul class='nav nav-pills'>
          <li>
            <a href='/'>
              <span class='glyphicon glyphicon-home'></span>
              Home
            </a>
          </li>
          <li>
            <a href='/doc/'>
              <span class='glyphicon glyphicon-book'></span>
              Documentation
            </a>
          </li>
          <li>
            <a href='/blog/'>
              <span class='glyphicon glyphicon-bullhorn'></span>
              Blog
            </a>
          </li>
          <li>
            <a href='/contact.html'>
              <span class='glyphicon glyphicon-inbox'></span>
              Contact
            </a>
          </li>
        </ul>
      </div>
      <ol class="breadcrumb"><li><a href="/">Home</a></li><li><a href='../'>Howl 0.4 Documentation</a></li><li>Spec</li><li>Spec - howl.ustrings</li></ol>
      <div class="spec-group spec-group-1">&#x000A;&#x000A;<h1 id="howl.ustrings">howl.ustrings</h1>&#x000A;&#x000A;<h4 id=".ulen-holds-the-number-characters-in-the-string">.ulen holds the number characters in the string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="s1">'foo'</span><span class="p">).</span><span class="n">ulen</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="s1">'åäö'</span><span class="p">).</span><span class="n">ulen</span></pre>&#x000A;&#x000A;<h4 id=".ulower-is-a-lower-cased-version-of-the-string">.ulower is a lower cased version of the string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'abcåäö'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="s1">'aBCåÄÖ'</span><span class="p">).</span><span class="n">ulower</span></pre>&#x000A;&#x000A;<h4 id=".uupper-is-a-upper-cased-version-of-the-string">.uupper is a upper cased version of the string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ABCÅÄÖ'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="s1">'abcåäö'</span><span class="p">).</span><span class="n">uupper</span></pre>&#x000A;&#x000A;<h4 id=".ureverse-is-a-reversed-version-of-the-string">.ureverse is a reversed version of the string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'abcåäö'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="s1">'öäåcba'</span><span class="p">).</span><span class="n">ureverse</span></pre>&#x000A;&#x000A;<h4 id=".multibyte-is-true-if-the-string-contains-multibyte-characters">.multibyte is true if the string contains multibyte characters</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="p">(</span><span class="s1">'foo'</span><span class="p">).</span><span class="n">multibyte</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="p">(</span><span class="s1">'åäö'</span><span class="p">).</span><span class="n">multibyte</span></pre>&#x000A;&#x000A;<h4 id=".is_empty-is-true-for-the-empty-string">.is_empty is true for the empty string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="p">(</span><span class="s1">''</span><span class="p">).</span><span class="n">is_empty</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="p">(</span><span class="s1">' '</span><span class="p">).</span><span class="n">is_empty</span></pre>&#x000A;&#x000A;<h4 id=".is_blank-is-true-for-a-string-that-is-empty-or-only-contains-whitespace">.is_blank is true for a string that is empty or only contains whitespace</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="p">(</span><span class="s1">'\t\r\n'</span><span class="p">).</span><span class="n">is_blank</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="p">(</span><span class="s1">'x'</span><span class="p">).</span><span class="n">is_blank</span></pre>&#x000A;&#x000A;<h4 id=".stripped-contains-the-string-without-leading-or-trailing-whitespace">.stripped contains the string without leading or trailing whitespace</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="s1">'  \tfoo'</span><span class="p">).</span><span class="n">stripped</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="s1">'foo '</span><span class="p">).</span><span class="n">stripped</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="s1">'  \tfoo '</span><span class="p">).</span><span class="n">stripped</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="s1">'  \t'</span><span class="p">).</span><span class="n">stripped</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="s1">''</span><span class="p">).</span><span class="n">stripped</span></pre>&#x000A;&#x000A;<h4 id="ucompare(s1,-s2)-returns-negative,-0-or-positive-if-s1-is-smaller,-equal-or-greater-than-s2">ucompare(s1, s2) returns negative, 0 or positive if s1 is smaller, equal or greater than s2</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="s1">'a'</span><span class="o">\</span><span class="n">ucompare</span><span class="p">(</span><span class="s1">'b'</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="mi">0</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="s1">'a'</span><span class="o">\</span><span class="n">ucompare</span><span class="p">(</span><span class="s1">'ä'</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="mi">0</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="s1">'a'</span><span class="o">\</span><span class="n">ucompare</span><span class="p">(</span><span class="s1">'a'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="s1">'ö'</span><span class="o">\</span><span class="n">ucompare</span><span class="p">(</span><span class="s1">'ä'</span><span class="p">)</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">0</span></pre>&#x000A;&#x000A;<h4 id="is_valid_utf8(s)-return-true-for-valid-utf8-strings-only">is_valid_utf8(s) return true for valid utf8 strings only</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="p">(</span><span class="s1">'abc\194\128'</span><span class="p">).</span><span class="n">is_valid_utf8</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="p">(</span><span class="s1">'\127'</span><span class="p">).</span><span class="n">is_valid_utf8</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="p">(</span><span class="s1">'\128'</span><span class="p">).</span><span class="n">is_valid_utf8</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="p">(</span><span class="s1">'abc\194'</span><span class="p">).</span><span class="n">is_valid_utf8</span></pre>&#x000A;&#x000A;<h4 id="starts_with(s)-returns-true-if-the-string-starts-with-the-specified-string">starts_with(s) returns true if the string starts with the specified string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">starts_with</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">starts_with</span><span class="w"> </span><span class="s1">'foobar'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">starts_with</span><span class="w"> </span><span class="s1">'foobarx'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">starts_with</span><span class="w"> </span><span class="s1">'.oo'</span></pre>&#x000A;&#x000A;<h4 id="ends_with(s)-returns-true-if-the-string-ends-with-the-specified-string">ends_with(s) returns true if the string ends with the specified string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">ends_with</span><span class="w"> </span><span class="s1">'bar'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">ends_with</span><span class="w"> </span><span class="s1">'foobar'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">ends_with</span><span class="w"> </span><span class="s1">'barx'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">ends_with</span><span class="w"> </span><span class="s1">'.ar'</span></pre>&#x000A;&#x000A;<h4 id="contains(s)-returns-true-if-the-string-contains-the-specified-string">contains(s) returns true if the string contains the specified string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">contains</span><span class="w"> </span><span class="s1">'foobar'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">contains</span><span class="w"> </span><span class="s1">'bar'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">contains</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">contains</span><span class="w"> </span><span class="s1">'oba'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">contains</span><span class="w"> </span><span class="s1">'arx'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">contains</span><span class="w"> </span><span class="s1">'xfo'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">contains</span><span class="w"> </span><span class="s1">'.'</span></pre>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="usub">usub<span class="arg-list">(i, [j])</span></h2>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'aåäöx'</span></pre>&#x000A;&#x000A;<h4 id="operates-on-characters-instead-of-bytes">operates on characters instead of bytes</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'aåä'</span><span class="p">,</span><span class="w"> </span><span class="n">s</span><span class="o">\</span><span class="n">usub</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'aåä'</span><span class="p">,</span><span class="w"> </span><span class="n">s</span><span class="o">\</span><span class="n">usub</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">)</span></pre>&#x000A;&#x000A;<h4 id="adjusts-the-indexes-similarily-to-string.sub">adjusts the indexes similarily to string.sub</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'äöx'</span><span class="p">,</span><span class="w"> </span><span class="n">s</span><span class="o">\</span><span class="n">usub</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="c1">-- j defaults to -1</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'öx'</span><span class="p">,</span><span class="w"> </span><span class="n">s</span><span class="o">\</span><span class="n">usub</span><span class="w"> </span><span class="o">-</span><span class="mi">2</span><span class="w"> </span><span class="c1">-- i counts from back</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'aåäöx'</span><span class="p">,</span><span class="w"> </span><span class="n">s</span><span class="o">\</span><span class="n">usub</span><span class="w"> </span><span class="o">-</span><span class="mi">7</span><span class="w"> </span><span class="c1">-- is corrected to 1</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'aåäöx'</span><span class="p">,</span><span class="w"> </span><span class="n">s</span><span class="o">\</span><span class="n">usub</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">123</span><span class="w"> </span><span class="c1">-- j is corrected to last character</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">s</span><span class="o">\</span><span class="n">usub</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="c1">-- empty string when i &lt; j</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="character-access-using-indexing-notation">character access using indexing notation</h2>&#x000A;&#x000A;<h4 id="single-character-strings-can-be-accessed-using-indexing-notation">single character strings can be accessed using indexing notation</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'aåäöx'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="n">s</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ä'</span><span class="p">,</span><span class="w"> </span><span class="n">s</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span></pre>&#x000A;&#x000A;<h4 id="accesses-using-invalid-indexes-returns-an-empty-string">accesses using invalid indexes returns an empty string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'abc'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">s</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">s</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span></pre>&#x000A;&#x000A;<h4 id="the-index-can-be-negative-similarily-to-sub()">the index can be negative similarily to sub()</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'aåäöx'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ä'</span><span class="p">,</span><span class="w"> </span><span class="n">s</span><span class="p">[</span><span class="o">-</span><span class="mi">3</span><span class="p">]</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="umatch">umatch<span class="arg-list">(pattern [, init])</span></h2>&#x000A;&#x000A;<h4 id="init-specifies-a-character-offset">init specifies a character offset</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'ö'</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'äåö'</span><span class="o">\</span><span class="n">umatch</span><span class="w"> </span><span class="s1">'(%S+)()'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="if-init-is-greater-than-the-length-nil-is-returned">if init is greater than the length nil is returned</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="s1">'1'</span><span class="o">\</span><span class="n">umatch</span><span class="w"> </span><span class="s1">'1'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span></pre>&#x000A;&#x000A;<h4 id="accepts-regex-patterns">accepts regex patterns</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="s1">'ö'</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'/ö'</span><span class="o">\</span><span class="n">umatch</span><span class="w"> </span><span class="n">r</span><span class="s1">'\\p{L}'</span><span class="p">}</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="ugmatch">ugmatch<span class="arg-list">(pattern)</span></h2>&#x000A;&#x000A;<h4 id="returns-character-offsets-instead-of-byte-offsets">returns character offsets instead of byte offsets</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'föo bãr'</span><span class="w">&#x000A;</span><span class="n">gen</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">s</span><span class="o">\</span><span class="n">ugmatch</span><span class="w"> </span><span class="s1">'(%S+)()'</span><span class="w">&#x000A;</span><span class="n">rets</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="k">while</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">vals</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">gen</span><span class="o">!</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;  </span><span class="k">break</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="o">#</span><span class="n">vals</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="w">&#x000A;  </span><span class="n">append</span><span class="w"> </span><span class="n">rets</span><span class="p">,</span><span class="w"> </span><span class="n">vals</span><span class="w">&#x000A;&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'föo'</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'bãr'</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">rets</span></pre>&#x000A;&#x000A;<h4 id="accepts-regex-patterns">accepts regex patterns</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'well hello there'</span><span class="w">&#x000A;</span><span class="n">matches</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">m</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">m</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">s</span><span class="o">\</span><span class="n">ugmatch</span><span class="w"> </span><span class="n">r</span><span class="s1">'\\w+'</span><span class="p">]</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'well'</span><span class="p">,</span><span class="w"> </span><span class="s1">'hello'</span><span class="p">,</span><span class="w"> </span><span class="s1">'there'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">matches</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="ufind">ufind<span class="arg-list">(pattern [, init [, plain]])</span></h2>&#x000A;&#x000A;<h4 id="returns-character-offsets-instead-of-byte-offsets">returns character offsets instead of byte offsets</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'ä öx'</span><span class="o">\</span><span class="n">ufind</span><span class="w"> </span><span class="s1">'%s.+x()'</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="adjust-middle-of-sequence-position-returns-to-character-start">adjust middle-of-sequence position returns to character start</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'äöx'</span><span class="o">\</span><span class="n">ufind</span><span class="w"> </span><span class="s1">'%S'</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="init-specifies-a-character-offset">init specifies a character offset</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="s1">'ö'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'äåö'</span><span class="o">\</span><span class="n">ufind</span><span class="w"> </span><span class="s1">'(%S+)'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="if-init-is-greater-than-the-length-nil-is-returned">if init is greater than the length nil is returned</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="s1">'1'</span><span class="o">\</span><span class="n">ufind</span><span class="w"> </span><span class="s1">'1'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span></pre>&#x000A;&#x000A;<h4 id="accepts-regexes">accepts regexes</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'!ä öx'</span><span class="o">\</span><span class="n">ufind</span><span class="w"> </span><span class="n">r</span><span class="s1">'\\pL'</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="returns-empty-match-at-init-for-empty-string">returns empty match at init for empty string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'abc'</span><span class="o">\</span><span class="n">ufind</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="converts-position-matches-correctly">converts position matches correctly</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'åäö'</span><span class="o">\</span><span class="n">ufind</span><span class="w"> </span><span class="s1">'()%S+()'</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="rfind">rfind<span class="arg-list">(pattern [, init])</span></h2>&#x000A;&#x000A;<h4 id="searches-backward-from-end-using-byte-offsets">searches backward from end using byte offsets</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'äöxx'</span><span class="o">\</span><span class="n">rfind</span><span class="w"> </span><span class="s1">'xx'</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="searches-backward-from-init,-when-provided">searches backward from init, when provided</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'äöxxx'</span><span class="o">\</span><span class="n">rfind</span><span class="w"> </span><span class="s1">'x'</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="urfind">urfind<span class="arg-list">(text [, init])</span></h2>&#x000A;&#x000A;<h4 id="searches-backwards-from-end-using-char-offsets">searches backwards from end using char offsets</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'äöxäöx'</span><span class="o">\</span><span class="n">urfind</span><span class="w"> </span><span class="s1">'äö'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'äöxböx'</span><span class="o">\</span><span class="n">urfind</span><span class="w"> </span><span class="s1">'xböx'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'äöxböx'</span><span class="o">\</span><span class="n">urfind</span><span class="w"> </span><span class="s1">'äöx'</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="returns-nothing-for-no-matches">returns nothing for no matches</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'hello'</span><span class="o">\</span><span class="n">urfind</span><span class="w"> </span><span class="s1">'x'</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="searches-backwards-from-init,-when-provided">searches backwards from init, when provided</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'äöxäöx'</span><span class="o">\</span><span class="n">urfind</span><span class="w"> </span><span class="s1">'äö'</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'äöxäöx'</span><span class="o">\</span><span class="n">urfind</span><span class="w"> </span><span class="s1">'äö'</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">3</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'äöxäöx'</span><span class="o">\</span><span class="n">urfind</span><span class="w"> </span><span class="s1">'äö'</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'äöxäöx'</span><span class="o">\</span><span class="n">urfind</span><span class="w"> </span><span class="s1">'äö'</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">2</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="matches-text-entirely-before-init">matches text entirely before init</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'abcabc'</span><span class="o">\</span><span class="n">urfind</span><span class="w"> </span><span class="s1">'ab'</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="returns-empty-match-before-init-for-empty-string">returns empty match before init for empty string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'abc'</span><span class="o">\</span><span class="n">urfind</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="count">count<span class="arg-list">(s, pattern = false)</span></h2>&#x000A;&#x000A;<h4 id="returns-the-number-of-occurences-of-s-within-the-string">returns the number of occurences of s within the string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">count</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">count</span><span class="w"> </span><span class="s1">'o'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">count</span><span class="w"> </span><span class="s1">'x'</span></pre>&#x000A;&#x000A;<h4 id="s-is-evaluated-as-a-pattern-if-&lt;pattern&gt;-is-true">s is evaluated as a pattern if &lt;pattern&gt; is true</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="o">\</span><span class="n">count</span><span class="p">(</span><span class="s1">'%w'</span><span class="p">,</span><span class="w"> </span><span class="kc">true</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">count</span><span class="p">(</span><span class="n">r</span><span class="s1">'[ab]'</span><span class="p">,</span><span class="w"> </span><span class="kc">true</span><span class="p">)</span></pre>&#x000A;&#x000A;<h4 id="s-is-evaluated-as-a-pattern-if-it-is-a-regex,-regardless-of-&lt;pattern&gt;">s is evaluated as a pattern if it is a regex, regardless of &lt;pattern&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s1">'foobar'</span><span class="o">\</span><span class="n">count</span><span class="p">(</span><span class="n">r</span><span class="s1">'[ab]'</span><span class="p">)</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="byte_offset">byte_offset<span class="arg-list">(...)</span></h2>&#x000A;&#x000A;<h4 id="returns-byte-offsets-for-all-character-offsets-passed-as-parameters">returns byte offsets for all character offsets passed as parameters</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'äåö'</span><span class="o">\</span><span class="n">byte_offset</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="accepts-non-increasing-offsets">accepts non-increasing offsets</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'ab'</span><span class="o">\</span><span class="n">byte_offset</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="raises-an-error-for-decreasing-offsets">raises an error for decreasing offsets</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'Decreasing offset'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s1">'äåö'</span><span class="o">\</span><span class="n">byte_offset</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span></pre>&#x000A;&#x000A;<h4 id="raises-error-for-out-of-bounds-offsets">raises error for out-of-bounds offsets</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'out of bounds'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s1">'äåö'</span><span class="o">\</span><span class="n">byte_offset</span><span class="w"> </span><span class="mi">5</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'offset'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s1">'äåö'</span><span class="o">\</span><span class="n">byte_offset</span><span class="w"> </span><span class="mi">0</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'offset'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s1">'a'</span><span class="o">\</span><span class="n">byte_offset</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span></pre>&#x000A;&#x000A;<h4 id="when-parameters-is-a-table,-it-returns-a-table-for-all-offsets-within-that-table">when parameters is a table, it returns a table for all offsets within that table</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="p">},</span><span class="w"> </span><span class="s1">'äåö'</span><span class="o">\</span><span class="n">byte_offset</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="char_offset">char_offset<span class="arg-list">(...)</span></h2>&#x000A;&#x000A;<h4 id="returns-character-offsets-for-all-byte-offsets-passed-as-parameters">returns character offsets for all byte offsets passed as parameters</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'äåö'</span><span class="o">\</span><span class="n">char_offset</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="accepts-non-increasing-offsets">accepts non-increasing offsets</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'ab'</span><span class="o">\</span><span class="n">char_offset</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="raises-an-error-for-decreasing-offsets">raises an error for decreasing offsets</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'Decreasing offset'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s1">'äåö'</span><span class="o">\</span><span class="n">char_offset</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span></pre>&#x000A;&#x000A;<h4 id="raises-error-for-out-of-bounds-offsets">raises error for out-of-bounds offsets</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'out of bounds'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s1">'ab'</span><span class="o">\</span><span class="n">char_offset</span><span class="w"> </span><span class="mi">4</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'offset'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s1">'äåö'</span><span class="o">\</span><span class="n">char_offset</span><span class="w"> </span><span class="mi">0</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'offset'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s1">'a'</span><span class="o">\</span><span class="n">char_offset</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span></pre>&#x000A;&#x000A;<h4 id="when-parameters-is-a-table,-it-returns-a-table-for-all-offsets-within-that-table">when parameters is a table, it returns a table for all offsets within that table</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="p">},</span><span class="w"> </span><span class="s1">'äåö'</span><span class="o">\</span><span class="n">char_offset</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;</div>&#x000A;</div>
      <div class='footer text-muted'>
        <a href='/'>
          <img width="50" height="50" class="footer-logo" src="/images/howl.png" />
        </a>
        <div class='footer-follow'>
          <p>
            <a class='twitter-follow-button' data-lang='en' data-show-count='false' href='https://twitter.com/howleditor' rel='me'>
              Follow @howleditor
            </a>
          </p>
          <p>
            <a class='twitter-share-button' data-count='none' data-hashtags='howleditor' data-lang='en' data-text='The Howl Editor, a general purpose, light-weight customizable editor.' data-url='http://howl.io' href='https://twitter.com/share'>
              Tweet
            </a>
          </p>
        </div>
        <div class='footer-blurb'>
          <div>The Howl editor.</div>
          <div>
            Copyright 2012-2016
            <a class='alert-link' href='https://github.com/howl-editor/howl/contributors'>
              The Howl Developers.
            </a>
          </div>
        </div>
      </div>
    </div>
    <script>
      <!-- / GA -->
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-45283282-1', 'howl.io');
      ga('send', 'pageview');
      <!-- / Twitter -->
      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
      if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
      js.src="//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    </script>
  </body>
</html>
